package com.yimi.policyservice.service.impl;

import com.yimi.policyservice.entity.base.system.SysDataDict;
import com.yimi.policyservice.repository.SysDataDictRepository;
import com.yimi.policyservice.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DictServiceImpl implements DictService {

    @Autowired
    private SysDataDictRepository sysDataDictRepository ;
    @Override
    public List<SysDataDict> findByKey(String key) {
        return sysDataDictRepository.findByDataKeyOrderByDictDisplayOrder(key);
    }


    @Override
    public Map<String, String> getAllCode() {
        List<SysDataDict> dataDicts = sysDataDictRepository.findAll();
        Map<String,String> res = new HashMap<>();
        dataDicts.forEach(item->{
            res.put(item.getDictCode(),item.getDictName());
        });
        return res;
    }
}
